package com.koron.order.overhaul.service.impl;

import com.koron.common.core.util.CodeTools;
import com.koron.order.overhaul.bean.entity.OverhaulOrderMajorBean;
import com.koron.order.overhaul.bean.query.OverhaulOrderMajorQuery;
import com.koron.order.overhaul.mapper.OverhaulOrderMajorMapper;
import com.koron.order.overhaul.service.OverhaulOrderMajorService;
import com.koron.order.overhaul.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * (OverhaulOrderMajorBean)表服务实现类
 *
 * @author twcao
 * @since 2021-09-29 09:49:31
 */
@Service
public class OverhaulMajorServiceImpl implements OverhaulOrderMajorService {

    @Override
    public OverhaulOrderMajorBean queryById(SessionFactory factory, String majorId) {
        OverhaulOrderMajorMapper mapper = factory.getMapper(OverhaulOrderMajorMapper.class);
        OverhaulOrderMajorBean majorBean = mapper.queryById(majorId);
        return majorBean;
    }

    @Override
    public int saveOrUpdate(SessionFactory factory, List<OverhaulOrderMajorBean> beans) {
        Assert.notEmpty(beans, "专业集合不能为空");
        Assert.noNullElements(beans, "专业不能为空");
        OverhaulOrderMajorMapper mapper = factory.getMapper(OverhaulOrderMajorMapper.class);
        CommonUtils.update(beans);
        beans.forEach(major -> major.setId(StringUtils.isBlank(major.getId()) ? CodeTools.getCode32() : major.getId()));
        return mapper.saveOrUpdate(beans);
    }

    @Override
    public int deleteByOrderId(SessionFactory factory, String orderId) {
        OverhaulOrderMajorMapper mapper = factory.getMapper(OverhaulOrderMajorMapper.class);
        return mapper.deleteByOrderId(orderId);
    }

    @Override
    public int hiddenByOrderId(SessionFactory factory, String orderId) {
        OverhaulOrderMajorMapper mapper = factory.getMapper(OverhaulOrderMajorMapper.class);
        return mapper.hiddenByOrderId(orderId);
    }

    @Override
    public List<OverhaulOrderMajorBean> queryList(SessionFactory factory, OverhaulOrderMajorQuery query) {
        OverhaulOrderMajorMapper mapper = factory.getMapper(OverhaulOrderMajorMapper.class);
        return mapper.queryList(query);
    }
}
